﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace _11泛型
{
    class Monitor
    {


        public static void Show()
        {
            int x = 12345;
            long commonSecond;//普通类型方法耗费的时间
            long objectSecond;//Object类型方法耗费的时间
            long genericSecond;//泛型方法耗费的时间
            
            //普通方法测试模块 
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();//开始计时
                for (int i = 0; i < 500000000; i++)
                {
                    ShowInt(x);
                }
                watch.Stop();
                commonSecond = watch.ElapsedMilliseconds;
            }

            //Object方法测试模块 
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();//开始计时
                for (int i = 0; i < 500000000; i++)
                {
                    ShowObject(x);
                }
                watch.Stop();
                objectSecond = watch.ElapsedMilliseconds;
            }

            //泛型方法测试模块 
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();//开始计时
                for (int i = 0; i < 500000000; i++)
                {
                    Show<int>(x);
                }
                watch.Stop();
                genericSecond = watch.ElapsedMilliseconds;
            }


            Console.WriteLine("普通方法运行时间:{0}",commonSecond);
            Console.WriteLine("Object方法运行时间:{0}", objectSecond);
            Console.WriteLine("泛型方法运行时间:{0}", genericSecond);

        }

        //显示整数
        static void ShowInt(int x)
        {
            //Console.WriteLine("整型值是:{0}", x);
        }

        //object数据类型 在效率上很低
        static void ShowObject(object obj)
        {
            //Console.WriteLine(obj);
        }

        //泛型用法
        static void Show<T>(T t)
        {
            //Console.WriteLine(t.ToString());
        }



    }
}
